//
//  MYHomeBottomView.swift
//  NewMicroblog
//
//  Created by apple on 2016/10/26.
//  Copyright © 2016年 apple. All rights reserved.
//

import UIKit

class MYHomeTopView: UIView {
    
    var originalViewBottomeCons: Constraint?
    var statusViewModel: MYStatusViewModel?{
        didSet{
            iconView.my_setImage(urlStr: statusViewModel?.listModel?.user?.profile_image_url, placeholderImgName: "avatar_default_big")
            nameLabel.text = statusViewModel?.listModel?.user?.name
            memberView.image = statusViewModel?.mbrankImage
            avaterView.image = statusViewModel?.verifiedImage
            contentLable.text = statusViewModel?.listModel?.text
            sourceLabel.text = statusViewModel?.sourceStr
            timeLabel.text = statusViewModel?.timeStr
            originalViewBottomeCons?.uninstall()
            if (statusViewModel?.listModel?.pic_urls?.count)! > 0 {
                pictureView.isHidden = false
                pictureView.picUrls = statusViewModel?.listModel?.pic_urls
                self.snp_makeConstraints(closure: { (make) in
                    self.originalViewBottomeCons = make.bottom.equalTo(pictureView).offset(10).constraint
                })
            }else{
                pictureView.isHidden = true
                self.snp_makeConstraints(closure: { (make) in
                    self.snp_makeConstraints(closure: { (make) in
                        self.originalViewBottomeCons = make.bottom.equalTo(contentLable).offset(10).constraint
                    })
                })
            }
        }
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
     ///搭建界面
     func setupUI(){
//        backgroundColor = UIColor.blue
        addSubview(iconView)
        addSubview(nameLabel)
        addSubview(memberView)
        addSubview(timeLabel)
        addSubview(sourceLabel)
        addSubview(avaterView)
        addSubview(contentLable)
        addSubview(pictureView)
        iconView.snp_makeConstraints { (make) in
            make.top.equalTo(self).offset(7)
            make.size.equalTo(CGSize(width: 35, height: 35))
            make.left.equalTo(self).offset(8)
        }
        nameLabel.snp_makeConstraints { (make) in
            make.top.equalTo(iconView)
            make.left.equalTo(iconView.snp_right).offset(10)
        }
        memberView.snp_makeConstraints { (make) in
            make.centerY.equalTo(nameLabel)
            make.left.equalTo(nameLabel.snp_right).offset(10)
        }
        timeLabel.snp_makeConstraints { (make) in
            make.left.equalTo(nameLabel)
            make.bottom.equalTo(iconView)
        }
        sourceLabel.snp_makeConstraints { (make) in
            make.centerY.equalTo(timeLabel)
            make.left.equalTo(timeLabel.snp_right).offset(10)
        }
        avaterView.snp_makeConstraints { (make) in
            make.centerY.equalTo(iconView.snp_bottom)
            make.centerX.equalTo(iconView.snp_right)
        }
        contentLable.snp_makeConstraints { (make) in
            make.top.equalTo(iconView.snp_bottom).offset(10)
            make.left.equalTo(iconView)
            
        }
        pictureView.snp_makeConstraints { (make) in
            make.top.equalTo(contentLable.snp_bottom).offset(10)
            make.left.equalTo(contentLable)
            
        }
        self.snp_makeConstraints { (make) in
            self.originalViewBottomeCons = make.bottom.equalTo(pictureView).offset(10).constraint
        }
        
        
    
    }
    
    /// 创建子控件
    private lazy var iconView:UIImageView = UIImageView(imageName: "avatar_default_big")
    private lazy var nameLabel:UILabel = UILabel(title: "雨哥", fontSize: 13,textColor: UIColor.black)
    private lazy var memberView:UIImageView = UIImageView(imageName: "common_icon_membership_level1")
    private lazy var timeLabel:UILabel = UILabel(title: "几分钟前", fontSize: 12, textColor: UIColor.darkGray)
    private lazy var sourceLabel:UILabel = UILabel(title: "新浪新闻", fontSize: 13, textColor: UIColor.darkGray)
    private lazy var avaterView:UIImageView = UIImageView(imageName: "avatar_vgirl")
    private lazy var contentLable:UILabel = UILabel(title: "你好啊大雨个", fontSize: 14, textColor: UIColor.black, axWidth:SCREENWIDTH - 20)
    private lazy var pictureView: MYStatusPictureView = {
        let view = MYStatusPictureView()
        view.backgroundColor = UIColor.magenta
        return view
    }()
}
